package com.jzo2o.orders.manager.service.client;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.jzo2o.api.foundations.ServeApi;
import com.jzo2o.api.foundations.dto.response.ServeAggregationResDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class ServeClient {
    @Resource
    private ServeApi serveApi;

    @SentinelResource(value = "findById",fallback = "findByIdFallback",blockHandler = "findByIdBlockHandler")
    public ServeAggregationResDTO findById(Long id) {
        log.info("id:{}",id);
       return serveApi.findById(id);
    }

    public ServeAggregationResDTO findByIdFallback(Long id,Throwable t) {
        log.error("非限流、熔断等导致的异常执行的降级方法，id:{},throwable:", id, t);
        return null;
    }

    public ServeAggregationResDTO findByIdBlockHandler(Long id, BlockException e) {
        log.error("限流、熔断等导致的异常执行的降级方法，id:{},throwable:", id, e);
        return null;
    }
}
